package com.link.base.base.project.service;

import com.link.base.base.project.dao.mybatis.mapper.ProjectLossMapper;
import com.link.base.base.project.model.Project;
import com.link.base.base.project.model.ProjectLoss;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 项目失标
 *
 * @author 王昊
 * @date 2020-10-28 14:52:29
 */
@Service
public class ProjectLossServiceImpl extends BasicServiceImpl<ProjectLoss> implements ProjectLossService {

    @Resource
    private ProjectLossMapper    projectLossMapper;

    @Resource
    private ProjectService projectService;

    @Override
    public BasicMapper<ProjectLoss> getBasicMapper() {
        return projectLossMapper;
    }

    @Override
    public void beforUpsert(ProjectLoss entity) throws Exception {
        super.beforUpsert(entity);
        /**
         * 当点击【失标分析】按钮，并成功将该项目的失标详情页保存后，字段“是否定点”显示否。项目状态为已关闭
         */
        //1.新建项目实体，将失标分析实体项目ID存入项目实体
        Project project = new Project();
        project.setId(entity.getProjectId());
        //2.根据项目实体ID去项目表查询记录，为对应记录的‘是否定点’字段赋值否,项目状态为已关闭
        Project project1 = projectService.queryById(project);
        project1.setWinFlag("N");
        project1.setProjectStatus("Closed");
        projectService.update(project1);
    }

    /**
     * 项目失标报表
     * @param entity
     * @return
     */
    @Override
    public List<ProjectLoss> queryAllReasonNum(ProjectLoss entity) {
        return projectLossMapper.queryAllReasonNum(entity);
    }
}